<template>
	<view class="my-content">
		<view class="context_bigTitle">
			<text class="big">{{ data[$t('item.title')]||'' }}</text>
			<!-- <text class="vice">{{ data[$t('item.title')]||'' }}</text> -->
			<text class="time">{{ time('S', data.createtime) }}</text>
		</view>
		<view class="line"></view>
		<view class="content_body" style="word-break: break-all;">
			<text>
				{{ replaceChange(data[$t('item.con')]) }}
			</text>
		</view>
		<view class="flex flex-around posit-fixed width-all marg-t-10" style="bottom: 40px;" v-if="data.message_id>0">
			<u-button type="primary" shape="circle" class="font-14"
				style="padding: 0px 60rpx;background-color: #004CFF;color: #fff;" :loading="submit_loading"
				:disabled="submit_loading" @click="can_submit(data)">{{$t('加入会议')}}</u-button>
		</view>
		<permissionMeet ref="permissionMeet"
			v-show="platform=='android'&&plat=='app'&&tan_flag==true&&permissionsShow==true"></permissionMeet>
	</view>

</template>

<script>
	import {
		time
	} from "@/common/public";
	import permissionMeet from "@/components/permissionMeet.vue";
	export default {
		components: {
			permissionMeet
		},
		data() {
			return {
				id: 0,
				data: {},
				submit_loading: false,
				plat: 'app',
				tan_flag: false,
				platform: '',
				permissionsShow: false
			};
		},
		onLoad(option) {
			const systemInfo = uni.getSystemInfoSync();
			if (uni.getStorageSync('platform')) {
				this.platform = uni.getStorageSync('platform');
			} else {
				this.platform = systemInfo.platform;
			}
			this.permissionsShow = uni.getStorageSync('permissionsShow');
			this.id = Number(option.id)
			this.$u.api.basic.getNoticeDetail({
				id: this.id
			}).then(res => {
				this.data = res
				console.log(this.data);
			})

		},
		onShow() {
			const that = this
			that.plat = uni.getStorageSync('plat')
			if (that.data.message_id > 0) {
				if (that.platform == 'android') {
					if (that.plat == 'app') {
						if (that.$refs.permissionMeet) {
							that.$refs.permissionMeet.checkRecordPermission()
							that.$refs.permissionMeet.checkPhotoPermission()
						}
						setTimeout(() => {
							if ((uni.getStorageSync('CAMERA_permission') == 1) && (uni.getStorageSync(
									'record_permission') == 1)) {
								that.tan_flag = false
							} else {
								that.tan_flag = true

							}
							uni.setNavigationBarTitle({
								title: '     '
							})
						}, 2000)
					}
				}
			}
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t("系统通知详情")
			})
		},
		methods: {
			time,
			replaceChange(str) {
				if (!!str) {
					return str.replace(/<br\/>/g, '\n\n')
				} else {
					return "";
				}

			},
			can_submitChange(data) {
				this.$u.api.user.meeting_check({
					id: data.message_id
				}).then(res => {
					if (res == '') {
						uni.showModal({
							content: this.$t('暂无视频会议'),
							showCancel: false,
							confirmText: this.$t('确定'),
						})
						return false
					}
					if (res.not_started == 1) {
						uni.showModal({
							content: this.$t('会议未开始'),
							showCancel: false,
							confirmText: this.$t('确定'),
						})
						return false
					}
					if (res.status == 2) {
						uni.showModal({
							content: this.$t('暂无视频会议'),
							showCancel: false,
							confirmText: this.$t('确定'),
						})
						return false
					}
					if (res.end_time > 0) {
						uni.showModal({
							content: this.$t('会议已结束'),
							showCancel: false,
							confirmText: this.$t('确定'),
						})
						return false
					}
					let typeUrl = '/pages/user/meetingJion/meeting?'
					uni.navigateTo({
						url: typeUrl + 'meetingRoomId=' + data.message_id + '&startMeetingId=' + res
							.user_id
					})
				})
			},
			can_submit(data) {
				//end_time
				if (uni.getStorageSync("user_id")) {
					if (this.platform == 'android') {
						if (this.plat == 'app') {
							if (this.$refs.permissionMeet) {
								this.$refs.permissionMeet.checkRecordPermission()
								this.$refs.permissionMeet.checkPhotoPermission()
							}
							setTimeout(() => {
								if ((uni.getStorageSync('CAMERA_permission') == 1) && (uni.getStorageSync(
										'record_permission') == 1)) {
									this.tan_flag = false
									this.can_submitChange(data)
								} else {
									this.tan_flag = true
								}
								uni.setNavigationBarTitle({
									title: '     '
								})
							}, 2000)
						}
					} else {
						this.can_submitChange(data)
					}
				} else {
					uni.showToast({
						title: this.$t('请先登录'),
						icon: "none"
					})
					setTimeout(() => {
						this.$u.route('/pages/user/login/login')
					}, 2000)
				}
			}

		},
	}
</script>

<style lang="scss" scoped>
	.my-content {
		display: flex;
		flex-direction: column;

		.line {
			height: 2rpx;
			border: 2rpx solid #E5E5E5;

		}

		.context_bigTitle {
			display: flex;
			flex-direction: column;
			padding: 34.88rpx;

			.big {
				font-size: 31rpx;
				font-weight: 600;
				color: #1C1C1C;
				line-height: 44rpx;
				margin-bottom: 6.98rpx;
			}

			.vice {
				font-size: 28rpx;

				font-weight: 400;
				color: #1C1C1C;
				line-height: 30rpx;
				margin-bottom: 6.98rpx;
			}

			.time {
				font-size: 26rpx;

				font-weight: 400;
				color: #1C1C1C;
				line-height: 30rpx;
			}
		}
	}

	.content_body {
		padding: 36.63rpx;
	}
</style>